import { UIOpacity, Vec3, tween, v3 } from "cc";
import OutsideClose from "../comps/OutsideClose";
import Foundation from "./Foundation";
import Gui from "./GuiMgr";

export default class BasePopup extends Foundation {
    public get data(): any { return this._data_$abc; }
    public setData(data: any) { this._data_$abc = data; }

    protected onLoad(): void {
        this.getComponent(OutsideClose)!.initTouchCallback(() => {
            this.onClickClose();
        });
        this.onEnterAnim();
        super.onLoad();
    }

    protected onEnterAnim() {
        let uiOpacity = this.getComponent(UIOpacity);
        if (uiOpacity) {
            uiOpacity.opacity = 0;
            tween(uiOpacity).to(0.2, { opacity: 255 }).start();
            tween(this.node).to(0.2, { scale: v3(1.05, 1.05, 1.05) }).to(0.06, { scale: Vec3.ONE }).start();
        }
    }

    public setBlankCloseLock(locked: boolean) {
        this.getComponent(OutsideClose)!.setLocked(locked);
    }

    /**
     * 设置当前类后缀标签
     */
    get suffix(): string { return this._suffix_$abc; }
    set suffix(s: string) { this._suffix_$abc = s; }


    /**
     * 当前 Popup 是否需要显示 mask
     */
    get isHideMask(): boolean { return this._isHideMask_$abc; }
    set isHideMask(v: boolean) { this._isHideMask_$abc = v; }


    /**
     * 关闭弹窗
     */
    public onClickClose() {
        this.removeAllClock();
        const uuid = this._suffix_$abc ? `${this.node.name}_${this._suffix_$abc}` : this.node.name;
        Gui.closePopup(uuid);
    }


    ////
    //private
    private _data_$abc: any = null;
    private _suffix_$abc: string = '';
    private _isAnimCompleted_$abc = false;
    private _isHideMask_$abc: boolean = true;
}